Discord Agent

工作流概述

这是一个包含13个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "A4hqQNFLymCRKnYK",
  "meta": {
    "instanceId": "5a64ae2dac98d415b280f5a86dd824858150b2ae6e4b41f2e62e7315042262b3",
    "templateCredsSetupCompleted": true
  },
  "name": "Discord Agent",
  "tags": [],
  "nodes": [
    {
      "id": "b0f78e4d-e6f9-496c-a9d1-f2ec17612770",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        80,
        60
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "Task"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "3e185fb3-0b5f-4ba6-b382-c332cefa727e",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        380,
        120
      ],
      "parameters": {
        "text": "={{ $json.Task }}{{ $json.chatInput }}",
        "options": {
          "systemMessage": "You are a helpful assistant In Charge OF managing Discord always use channel id to reference channels. Always convert and output text in stylish discord formats. Reduce Text To 1800 characters Max.

Before sending any message absolutely ensure it is less than 1800 characters

You can Use One tool to send to free guides channel and another for ai-tools channel. make sure to read tool descriptions"
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "1aa1b4df-71af-4b85-9a6e-b371a2349598",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        380,
        280
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "F4px3oxuWY5zBrvn",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d6f59c6e-3bc0-4e85-8b89-b1a480db5317",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        80,
        240
      ],
      "webhookId": "913628ac-d409-49fa-8a34-a11349a30da6",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "f0aa9420-0207-4f6b-a659-ef89104e4925",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        540,
        280
      ],
      "parameters": {
        "sessionKey": "={{ $json.Task }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "6b77b8f1-8fd2-4b0b-8993-3567d03b8b9b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        780,
        320
      ],
      "parameters": {
        "color": 4,
        "width": 460,
        "height": 260,
        "content": "## Discord Management Tools"
      },
      "typeVersion": 1
    },
    {
      "id": "8947bfd3-88ed-48e5-a07f-c012cc3202c6",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        40
      ],
      "parameters": {
        "color": 5,
        "width": 360,
        "height": 380,
        "content": "## Main Discord Manager Agent"
      },
      "typeVersion": 1
    },
    {
      "id": "7fb0e4b2-5e66-4b3a-a976-926a4427f3c5",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 3,
        "width": 260,
        "height": 400,
        "content": "## Trigger Automation "
      },
      "typeVersion": 1
    },
    {
      "id": "d100828e-6877-427d-ab8c-8486970b17e6",
      "name": "Discord",
      "type": "n8n-nodes-base.discordTool",
      "position": [
        960,
        420
      ],
      "webhookId": "aa558762-c5da-491d-9881-1a091632864f",
      "parameters": {
        "sendTo": "=channel",
        "userId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "content": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "guildId": {
          "__rl": true,
          "mode": "list",
          "value": "1236784625196601386",
          "cachedResultUrl": "https://discord.com/channels/1236784625196601386",
          "cachedResultName": "YungCEO SOCIETY💰"
        },
        "options": {},
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "1352547978308485192",
          "cachedResultUrl": "https://discord.com/channels/1236784625196601386/1352547978308485192",
          "cachedResultName": "ai-tools"
        },
        "descriptionType": "manual",
        "toolDescription": "Use this tool to post a message in ai-tools discord channel"
      },
      "credentials": {
        "discordBotApi": {
          "id": "ENuG6EzBN712IDLU",
          "name": "Motion Assistant"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d6dc1210-4049-4fa6-9896-67e8353db922",
      "name": "Discord1",
      "type": "n8n-nodes-base.discordTool",
      "position": [
        1080,
        420
      ],
      "webhookId": "7e07794e-e474-46c8-a23c-e9440a61d87b",
      "parameters": {
        "guildId": {
          "__rl": true,
          "mode": "list",
          "value": "1236784625196601386",
          "cachedResultUrl": "https://discord.com/channels/1236784625196601386",
          "cachedResultName": "YungCEO SOCIETY💰"
        },
        "options": {},
        "operation": "getAll",
        "returnAll": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Return_All', ``, 'boolean') }}"
      },
      "credentials": {
        "discordBotApi": {
          "id": "ENuG6EzBN712IDLU",
          "name": "Motion Assistant"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "1908e48f-51a7-4d42-a543-622a28c22136",
      "name": "Discord2",
      "type": "n8n-nodes-base.discordTool",
      "position": [
        820,
        420
      ],
      "webhookId": "aa558762-c5da-491d-9881-1a091632864f",
      "parameters": {
        "sendTo": "=channel",
        "userId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "content": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "guildId": {
          "__rl": true,
          "mode": "list",
          "value": "1236784625196601386",
          "cachedResultUrl": "https://discord.com/channels/1236784625196601386",
          "cachedResultName": "YungCEO SOCIETY💰"
        },
        "options": {},
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "1352242462520901632",
          "cachedResultUrl": "https://discord.com/channels/1236784625196601386/1352242462520901632",
          "cachedResultName": "free-guides"
        },
        "descriptionType": "manual",
        "toolDescription": "Use this tool to post a message in free-guides discord channel"
      },
      "credentials": {
        "discordBotApi": {
          "id": "ENuG6EzBN712IDLU",
          "name": "Motion Assistant"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "557189d6-d5f3-4059-b349-9c3a9b642083",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1000,
        -1300
      ],
      "parameters": {
        "color": 4,
        "width": 1340,
        "height": 1220,
        "content": "# N8N Discord Workflow Setup Guide

## Prerequisites
- N8N account
- Discord bot
- OpenAI API key
- Discord server access

## 1. Discord Bot Creation
### Steps
- Open Discord Developer Portal
- Create new application
- Generate bot token
- Add bot to server
- Set permissions:
  - Send Messages
  - Read Message History
  - View Channels

### Required Info
- Guild (Server) ID
- Channel IDs:
  - AI Tools Channel
  - Free Guides Channel

## 2. Credential Configuration
### Discord Bot Credentials
- Go to N8N Credentials section
- Create 'Discord Bot API' credential
- Enter bot token
- Name credential (e.g., 'Motion Assistant')

### OpenAI Credentials
- Create 'OpenAI API' credential
- Enter API key
- Name credential (e.g., 'OpenAI Account')

## 3. Workflow Setup
### AI Agent Configuration
- Customize system message
- Define character limits
- Specify output format

### Trigger Types
1. Workflow Execution Trigger
2. Direct Chat Message Trigger

"
      },
      "typeVersion": 1
    },
    {
      "id": "9b554c72-cb38-43d8-abcf-1bf48ee4fcec",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -1200
      ],
      "parameters": {
        "width": 1200,
        "height": 880,
        "content": "## Workflow Operation Modes
### Mode 1: Workflow Trigger
- Execute from another workflow
- Input: Task/message string
- Use cases:
  - Automated messaging
  - Scheduled updates
  - External event triggers

### Mode 2: Chat Trigger
- Webhook-based activation
- Process flow:
  1. Receive message
  2. AI Agent processing
  3. Generate response
  4. Maintain context

## Customization Points
- Modify AI system message
- Adjust character limits
- Configure channel interactions
- Select OpenAI model

## Potential Enhancements
- Error handling
- Advanced conversation memory
- Additional channel tools
- Message filtering

## Troubleshooting
- Verify bot permissions
- Check API credentials
- Validate character limits
- Confirm channel IDs"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8a8376c5-04e5-42da-9031-a9be0a34c211",
  "connections": {
    "Discord": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Discord1": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Discord2": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Executeworkflowtrigger
  • @N8N/N8N Nodes Langchain.Agent
  • @N8N/N8N Nodes Langchain.Lmchatopenai
  • @N8N/N8N Nodes Langchain.Chattrigger
  • @N8N/N8N Nodes Langchain.Memorybufferwindow

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作